var app=getApp();
Page({
  data: {
    collegename:"",
    isSelect:false,//展示类型？
    college:null,
    collegeLength:2,
    type:"",
    selectArray:[],
    colleged:null,//当前选择的院系
    userid:"",
  },
  onLoad: function (options) {
    var that=this;
    that.setData({
      userid:options.userid
    })

    wx.request({
			url: app.globalData.Url+'/wxstudent/wxGetCollegeName',
			data:{
				collegeid:options.collegeid
			},
      method:'POST',
      header:{
        'content-type':'application/x-www-form-urlencoded'
      },
      success:function(req){
				var list=req.data;
        that.setData({
          collegename:list[0].collegename
        })
      }
    })
  
    wx.request({
			url: app.globalData.Url+'/wxstudent/wxGetCollege',
			data:{},
      method:'POST',
      header:{ 'content-type':'application/x-www-form-urlencoded' },
      success:function(req){
        var list=req.data;
        console.log("xueyuan:"+list[1].collegename)
        var array;
        array=[];
        for(let i=0;i<list.length;i++){
          array.push(list[i].collegename)
        }
        that.setData({
          college:list,
          collegeLength:list.length,
          selectArray:array
        })
      }
    })

  },

  //点击控制下拉框的展示、隐藏
  select:function(){
    var isSelect = this.data.isSelect
    this.setData({ isSelect:!isSelect})
  },
  //点击下拉框选项，选中并隐藏下拉框
  getType:function(e){
    let value = e.currentTarget.dataset.type
    this.setData({
      type:value.collegename ,
      isSelect: false,
    })
  },

  submit: function () {
    wx.request({
			url: app.globalData.Url+'/wxstudent/wxSetCollegeBySId',
			data:{
        studentId:this.data.userid,
				collegeId:this.data.colleged.collegeid
			},
      method:'POST',
      header:{
        'content-type':'application/x-www-form-urlencoded'
      },
      success:function(req){
        if(req.data>0){
          wx.showToast({
            title: '修改成功！',
            icon:'success',
            duration:1500 //提示的延迟的时间
          })
        }
      }
    })
  },

  bindPickerChange: function(e) {
    var colleged=this.data.college.find(item=>{
      return item.collegeid==e.detail.value
    })
    this.setData({
      colleged: colleged
    })
  },
})